// DialogTransparency.cpp : implementation file
//

#include "stdafx.h"
#include "WP3.h"
#include "DialogTransparency.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDialogTransparency dialog


CDialogTransparency::CDialogTransparency(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogTransparency::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialogTransparency)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDialogTransparency::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogTransparency)
	DDX_Control(pDX, IDC_BUTTON_COLOR, m_colorbtn);
	DDX_Control(pDX, IDC_SLIDER_TRANS, m_slider);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialogTransparency, CDialog)
	//{{AFX_MSG_MAP(CDialogTransparency)
	ON_WM_HSCROLL()
	ON_BN_CLICKED(IDC_CHECK_ISENABLE, OnCheckIsEnable)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogTransparency message handlers

BOOL CDialogTransparency::OnInitDialog() 
{
	CDialog::OnInitDialog();
	

	TRDLG(IDOK,IDS_BUTTONOK);
	TRDLG(IDCANCEL,IDS_BUTTONCANCEL);
	TRDLG(IDC_CHECK_ISALPHA,IDS_ISALPHA);
	TRDLG(IDC_CHECK_ISENABLE,IDS_ISENABLE);
	TRDLG(IDC_STATIC_INVISIBLE,IDS_INVISIBLE);
	TRDLG(IDC_STATIC_VISIBLE,IDS_VISIBLE);
	TRDLG(IDC_STATIC_VISIBLE,IDS_VISIBLE);
	TRDLG(IDC_STATIC_GLOBALBG,IDS_GLOBALBG);

	SetWindowText(TR(IDS_TRANSPARENCY));

	((CButton*)GetDlgItem(IDC_CHECK_ISENABLE))->SetCheck(s_IsTrans=="1" ? 1 : 0);
	((CButton*)GetDlgItem(IDC_CHECK_ISALPHA))->SetCheck(s_IsAlpha=="1" ? 1 : 0);

	int trans=atoi(s_Transparency);
	m_slider.SetRange(0,255,FALSE);
	m_slider.SetPos(trans);
	m_slider.SetTicFreq(64);

	UpdateTransValue();

	m_colorbtn.currentcolor=atol(s_TransColor);

	OnCheckIsEnable();
	
	return TRUE;
}

void CDialogTransparency::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	UpdateTransValue();
	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CDialogTransparency::UpdateTransValue()
{
	CString S;
	S.Format("%i%%",100-(m_slider.GetPos()*100/255));
	GetDlgItem(IDC_STATIC_TRANSVALUE)->SetWindowText(S);
	UpdateData(FALSE);
}

void CDialogTransparency::OnOK() 
{
	s_IsTrans.Format("%i",((CButton*)GetDlgItem(IDC_CHECK_ISENABLE))->GetCheck());
	s_IsAlpha.Format("%i",((CButton*)GetDlgItem(IDC_CHECK_ISALPHA))->GetCheck());
	s_Transparency.Format("%i",m_slider.GetPos());
	s_TransColor.Format("%i",m_colorbtn.currentcolor);
	CDialog::OnOK();
}

#define EW(ID,F) GetDlgItem(ID)->EnableWindow(F)

void CDialogTransparency::OnCheckIsEnable() 
{
	BOOL isEnable=(((CButton*)GetDlgItem(IDC_CHECK_ISENABLE))->GetCheck()==1);
	EW(IDC_CHECK_ISALPHA,isEnable);
	EW(IDC_SLIDER_TRANS,isEnable);
	EW(IDC_STATIC_TRANSVALUE,isEnable);
	EW(IDC_BUTTON_COLOR,isEnable);
	EW(IDC_STATIC_GLOBALBG,isEnable);
	EW(IDC_STATIC_INVISIBLE,isEnable);
	EW(IDC_STATIC_VISIBLE,isEnable);
	
}
